/* 
 * Pickup Dropoff Module Configuration GUI
 */


// data stores

RM.Pages.PickupDropoff_Config_Customer_PriceOption_JsonStore = new Ext.data.JsonStore({
    fields:[
    {
        name:'value',
        type:'string'
    },

    {
        name:'text',
        type:'string'
    }
    ],
    data: [
        {'value':'0','text': RM.Translate.Admin.PickupDropoff.Config.IncludeInPrice},
        {'value':'1','text': RM.Translate.Admin.PickupDropoff.Config.ItemiseSeperately}
    ]

});

// functions

RM.Pages.Functions.PickupDropoff_Config_Toolbar = {
    xtype : "panel",
    id : "rm_pages_modules_pickupdropoff_toolbar",
    bodyBorder : false,
    html : RM.Common.getToolbar([{image: RM.BaseLargeImageURL+"save.gif", label: RM.Translate.Common.Save, link: "RM.Pages.Functions.PickupDropoff_Config_save()"}])
};
RM.Toolbars.push(RM.Pages.Functions.PickupDropoff_Config_Toolbar);



RM.Pages.Functions.PickupDropoff_Config_save = function(){
    RM.Pages.PickupDropoff_Config_Panel.getForm().submit({
        params: {
            'priceoption' : Ext.getCmp('rm_pages_modules_pickupdropoff_price_combo').getValue(),
            'default_price' : Ext.getCmp('rm_pages_modules_pickupdropoff_default_price').getValue()
        },
        success: function(form, action) {
            var statusbar = Ext.getCmp('rm_pages_modules_pickupdropoff_config_statusbar');
            statusbar.setStatus({
                text: RM.Translate.Admin.GMaps.Main.SaveOK,
                iconCls: 'ok-icon'
            });
        },
        failure: function() {
            var statusbar = Ext.getCmp('rm_pages_modules_pickupdropoff_config_statusbar');
            statusbar.setStatus({
                text: RM.Translate.Common.Failed,
                iconCls: 'failed-icon'
            });
        },
        waitMsg: RM.Translate.Common.Saving,
        waitTitle: RM.Translate.Common.PleaseWait
    });
};

RM.Pages.Functions.PickupDropoff_ConfigJson = function(responseObject) {

    // create a mask assigned to rm_pages_plugins_gmaps_main_form
    var myMask = new Ext.LoadMask('rm_pages_modules_pickupdropoff_config_main_form', {
        msg: RM.Translate.Common.PleaseWait,
        msgCls: "RM_Loading_Mask_Msg_Hidden" // hide the msg
    });
    myMask.show();

    Ext.getCmp("rm_pages_modules_pickupdropoff_price_combo").setValue(responseObject[0].priceoption);
    Ext.getCmp("rm_pages_modules_pickupdropoff_default_price").setValue(responseObject[0].default_price);


    // render the forms and toolbars
    Ext.getCmp('rm_pages_modules_pickupdropoff_config_main_form').render();
    Ext.getCmp('rm_pages_modules_pickupdropoff_config_main_form').doLayout();
    Ext.getCmp('toolbar_panel').layout.setActiveItem('rm_pages_modules_pickupdropoff_toolbar');
    Ext.getCmp('content-panel').layout.setActiveItem('rm_pages_modules_pickupdropoff_config_main_form');

    myMask.hide();

};

// form objects

RM.Pages.PickupDropoff_Config_PriceOption_Combo = {
    id : "rm_pages_modules_pickupdropoff_price_combo",
    name : "rm_pages_modules_pickupdropoff_price_combo_name",
    hiddenName : "rm_pages_modules_pickupdropoff_price_combo_hidden",
    xtype : "combo",
    fieldLabel : RM.Translate.Admin.PickupDropoff.Config.PriceOption,
    store : RM.Pages.PickupDropoff_Config_Customer_PriceOption_JsonStore,
    mode: "local",
    triggerAction: 'all',
    selectOnFocus: true,
    valueField: 'value',
    displayField: 'text',
    allowBlank: false,
    width: 220
};

RM.Pages.PickupDropoff_Config_PriceOption_Default_Price = {
    xtype : "textfield",
    id : "rm_pages_modules_pickupdropoff_default_price",
    name : "rm_pages_modules_pickupdropoff_default_price",
    fieldLabel : RM.Translate.Admin.PickupDropoff.Config.DefaultPrice,
    width : 220
};

RM.Pages.PickupDropoff_Config_Settings_Fieldset = new Ext.form.FieldSet({
    id: "rm_pages_modules_pickupdropoff_config_fieldset",
    title: RM.Translate.Admin.PickupDropoff.Config.Settings,
    autoHeight: true,
    layout: 'form',
    bodyBorder : false,
    items: [
        RM.Pages.PickupDropoff_Config_PriceOption_Combo,
        RM.Pages.PickupDropoff_Config_PriceOption_Default_Price
    ]
});

RM.Pages.PickupDropoff_Config_Panel = new Ext.FormPanel({
    id : 'rm_pages_modules_pickupdropoff_config_main_form',
    title: RM.Translate.Admin.PickupDropoff.Config.Title,
    bodyStyle : "padding:10px;",
    items : [
        RM.Pages.PickupDropoff_Config_Settings_Fieldset
    ],
    url : RM.Common.AssembleURL({
        controller: 'PickupDropoff',
        action: 'updateconfigjson'
    }),
    bbar: new Ext.ux.StatusBar({
        id: 'rm_pages_modules_pickupdropoff_config_statusbar',
        items: []
    })
});


RM.Main.Pages.push(RM.Pages.PickupDropoff_Config_Panel);